import React from 'react';
import {connect} from 'react-redux';
import {withRouter} from 'react-router-dom';
import {Button} from 'antd';
import {exitLogin} from '../../api/person';
import action from '../../store/action/index';

class Info extends React.Component {
    constructor(props, context) {
        super(props, context);
    }

    componentWillMount() {
        let {baseInfo, queryBaseInfo} = this.props;
        if(!baseInfo){
            baseInfo = queryBaseInfo();
        }
    }

    render() {
        let {baseInfo} = this.props;
        if (!baseInfo) return '';
        let {name, email, phone} = baseInfo;

        return <div className='personBaseInfo'>
            <div>
                <div>UserName:</div>
                <p>{name}</p>
            </div>
            <div>
                <div>Email:</div>
                <p>{email}</p>
            </div>
            <div>
                <div>Phone:</div>
                <p>{phone}</p>
            </div>

            <Button type='danger' onClick={async (ev) => {
                await this.props.logout();
                // exitLogin();
                this.props.history.push('/person');
            }}>Logout</Button>

            {/* <Button type='primary' onClick={async (ev) => {
                this.props.history.push('/candidate');
            }}>Go Home</Button> */}
        </div>;
    }
}

export default withRouter(connect(state => ({...state.person}), action.person)(Info));